<div class="section">
    <include file="header" />
    <div class="sysytem-app-main">
        <div class="panel panel-default">
          <div class="panel-body">
          <div class="pull-right top-margin-10">
            <a href="javascript:void(0);" data-remote-url="<{$remote}>" class="btn btn-info btn-sm show-modal" >添加分类</a>
          </div>
          <table class="table table-condensed table-hover font-size-1 table-boder-none">
          <colgroup>
            <col width="10%"></col>
            <col width="70%"></col>
            <col width="20%"></col>
          </colgroup>
            <thead>
                <tr>
                    <th>显示排序</th>
                    <th>菜单名称</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            <if condition="$data">
                <volist name="data" id="vo">
                    <tr>
                        <td><{$vo.order_sort}></td>
                        <td>
                        <{$vo.node_name}>
                        </td>
                        <td>
                        <a href="javascript:void(0);" data-remote-url="<{$vo.del_url}>" class="text-danger del-modal">删除</a>
                        &nbsp;|&nbsp;
                        <a href="javascript:void(0);" data-remote-url="<{$vo.edit_url}>"  class="text-primary show-modal">编辑</a>
                        </td>
                    </tr>
                    <if condition="$vo['child']">
                        <volist name="vo['child']" id="sub" >
                            <tr>
                                <td><{$sub.order_sort}></td>
                                <td>
                                <span class="tab-sign"></span><{$sub.node_name}>
                                </td>
                                <td>
                                <a href="javascript:void(0);" data-remote-url="<{$sub.del_url}>" class="text-danger del-modal">删除</a>
                                &nbsp;|&nbsp;
                                <a href="javascript:void(0);" data-remote-url="<{$sub.edit_url}>"  class="text-primary show-modal">编辑</a>
                                </td>
                            </tr>
                        </volist>
                    </if>
                </volist>
                <else />
                <tr>
                    <td colspan="3" class="text-center">暂无数据</td>
                </tr>
                    
            </if>
            </tbody>
          </table>
          </div>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="add-cat" tabindex="-1" role="dialog" aria-labelledby="addCatLabel">
    <div class="modal-dialog" role="document" aria-hidden="true">
        <div class="modal-content save-cat">
            
        </div>
    </div>
</div>

<div class="modal fade" id="del-cat" tabindex="-1" role="dialog" aria-labelledby="delCatLabel">
    <div class="modal-dialog modal-sm" role="document" aria-hidden="true">
        <div class="modal-content del-cat">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="gridSystemModalLabel">删除分类</h4>
            </div>
            <div class="modal-body">
                    删除此分类，此分类下所属文章将变为未分类，确定删除吗？
                  </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" id="del-cat-sure">确定</button>
            </div>
        </div>
    </div>
</div>
<script>
    var showModal = $('.show-modal');
    showModal.each(function(){
        var $this = $(this);
        $this.on('click',function(){
            var remoteUrl = $(this).attr('data-remote-url');
            $.get(remoteUrl,function(rs){
            	if(rs.status == 0)
            	{
            		$('#messagebox').message(rs.info);
            		
            	}else
            	{
            		$('.save-cat').html(rs);
                    $('#add-cat').modal('toggle');
            	}
            	
            	if(rs.url)
            	{
            		window.location.href = rs.url;
            	}
                
            });
            
        })
    })
    
    // 删除分类
    var delModal = $('.del-modal');
    delModal.each(function(){
        var $this = $(this);
        $this.on('click',function(){
            $('#del-cat').modal('show');
            $('#del-cat-sure').on('click',function(){
                $('#del-cat').modal('hide');
                var delUrl = $this.attr('data-remote-url');
                $.post(delUrl,function(re){
                    if(re.status == 0){
                        $('#messagebox').message(re.info);
                    }else{
                    	$this.parent().parent().remove();
                        $('#messagebox').message(re.info, 'success');
                    }
                    if(re.url)
                    {
                        window.location.href = re.url;
                    }
                })
            })
        })
    })
</script>